<?php
namespace app\api\model\operation;
use think\facade\Db;

class Rank{
	/**
	 * @title 查询畅销艺术家
	 */
	public function findArtRank($_where,$_field,$_user_id){
		return Db::name("user")->alias("u")
				->leftJoin("user_focus f","f.focus_id=u.id and f.user_id=".$_user_id)
				->where($_where)
				->field($_field)
				->find();
	}
	
	public function selectArtRank($_where,$_field,$_limit,$_order,$_user_id)
	{
		$_data=Db::name("user")->alias("u")
				->leftJoin("user_focus f","f.focus_id=u.id and f.user_id=".$_user_id)
				->where($_where)
				->field($_field)
				->limit(current($_limit),end($_limit))
				->order($_order)
				->select();
		return !empty($_data)?$_data->toArray():[];				
	}
	
	public function selectWork($_where,$_field,$_limit,$_order="id asc"){
		$_data=Db::name("opus")
			->where($_where)
			->field($_field)
			->limit(current($_limit),end($_limit))
			->order($_order)
			->select();
		return !empty($_data)?$_data->toArray():[];	
	}
	public function getLastSql(){
		return Db::name("opus")->getLastSql();
	}
	
	public function findWorkRank($_where,$_field)
	{
		return Db::name("opus")->alias("o")
			->join("user u","u.id=o.writer_id")
			->where($_where)->field($_field)->find();
	}
	
	public function selectWorkRank($_where,$_field,$_limit,$_order)
	{
		$_data=Db::name("opus")->alias("o")
			->join("user u","u.id=o.writer_id")
			->where($_where)
			->field($_field)
			->limit(current($_limit),end($_limit))->order($_order)->select();
		return !empty($_data)?$_data->toArray():[];
	}
	
	public function findShadowRank($_where,$_field,$_join){
		return Db::name("opus")->alias("o")
			->join("user u","u.id=o.writer_id")
			->join($_join,"shadow_order.opus_id=o.id")
			->where($_where)->field($_field)->find();
	}
	
	public function selectShadowRank($_where,$_field,$_limit,$_order,$_join){
		$_data=Db::name("opus")->alias("o")
			->join("user u","u.id=o.writer_id")
			->join($_join,"shadow_order.opus_id=o.id")
			->where($_where)
			->field($_field)
			->limit(current($_limit),end($_limit))->order($_order)->select();
		return !empty($_data)?$_data->toArray():[];
	}
}
?>